home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- * *
- * Copyright (c) 1991 Silicon Graphics, Inc. *
- * All Rights Reserved *
- * *
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI *
- * *
- * The copyright notice above does not evidence any actual of intended *
- * publication of such source code, and is an unpublished work by Silicon *
- * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
- * the property of Silicon Graphics, Inc. Any use, duplication or *
- * disclosure not specifically authorized by Silicon Graphics is strictly *
- * prohibited. *
- * *
- * RESTRICTED RIGHTS LEGEND: *
- * *
- * Use, duplication or disclosure by the Government is subject to *
- * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in *
- * Technical Data and Computer Software clause at DFARS 52.227-7013, *
- * and/or in similar or successor clauses in the FAR, DOD or NASA FAR *
- * Supplement. Unpublished - rights reserved under the Copyright Laws of *
- * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N. *
- * Shoreline Blvd., Mountain View, CA 94039-7311 *
- **************************************************************************
- *
- * File: submit.c
- *
- * Description: Submits a job for printing on the specified spooling system.
- *
- **************************************************************************/
-
-
- #ident "$Revision: 1.1 $"
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #ifdef sgi
- #include <getopt.h>
- #endif
- #include "spool.h"
-
-
- char *filename;
- char *title;
- char *printer;
- int num_copies = 1; /* Print one copy by default */
- int copy = 0; /* Spooler should link to file to be printed */
- int mail = 0; /* Do not send mail by default */
- char *options; /* Spooling system specific options */
- int spooler = SL_SPOOLER_NONE; /* Indicate no spooling system set */
-
-
- extern char *optarg;
- extern int optind;
-
-
- void usage(char*);
-
-
- main(int argc, char *argv[])
- {
- int ch;
- int errflag = 0, stdinflag = 0;
- register int i;
- SLPrintJob *job; /* Refer to SLSubmitJob(3) man page */
-
- /*
- * Process command line args
- */
- while ((ch = getopt(argc, argv, "n:d:cmt:p:s:")) != -1) {
- switch(ch) {
- case 'n': /* Number of copies */
- num_copies = atoi(optarg);
- break;
- case 'd': /* Destination printer */
- printer = optarg;
- break;
- case 'c': /* Copy or link to spool dir */
- copy = 1;
- break;
- case 'm': /* Send mail on completion */
- mail = 1;
- break;
- case 't': /* Banner title */
- title = optarg;
- break;
- case 'p': /* Spooler/Printer specific options */
- /* To send printer specific options */
- /* type '-p "-ozoom 0.5"' */
- options = optarg;
- break;
- case 's': /* Spooler to use */
- if (!strcmp(optarg, "bsd"))
- spooler = SL_SPOOLER_BSD;
- else if (!strcmp(optarg, "sysv"))
- spooler = SL_SPOOLER_SYSV;
- else
- errflag++;
- break;
- case '?':
- default:
- errflag++;
- break;
- }
- }
-
- /*
- * Get the filename(s). If no filename has been specified, read
- * stdin
- */
- if (argc == optind)
- stdinflag++;
- else {
- for (i = optind; i < argc; i++) {
- int len = strlen(argv[i]);
- if (filename)
- filename = (char*)realloc(filename, strlen(filename)+len+5);
- else {
- filename = (char*)malloc(len + 5);
- *filename = '\0';
- }
- (void)strcat(filename, argv[i]);
- (void)strcat(filename, " ");
- }
- }
-
- /*
- * If error print usage and exit
- */
- if (errflag) {
- usage(argv[0]);
- exit(1);
- }
-
- /*
- * If a spooling system has been specified set it
- */
- if (spooler != SL_SPOOLER_NONE) {
- if (SLSetSpooler(spooler) < 0) {
- SLPerror(argv[0]);
- exit(1);
- }
- }
-
- /*
- * Submit the job. Note that we do not need to get the default printer
- * name if no printer name was specified on the command-line. This is
- * because SLSubmitJob will determine the default printer automatically
- * if the printer parameter is NULL.
- */
- if (stdinflag) /* Print from standard input */
- job = SLSubmitJobFd(fileno(stdin), printer, num_copies, copy, mail,
- title, options);
- else /* Print from file(s) */
- job = SLSubmitJob(filename, printer, num_copies, copy, mail,
- title, options);
- if (job == NULL) {
- int j, status, nout;
- char **out_buf;
- SLPerror(argv[0]);
- if ((status = SLGetSpoolerError(&out_buf, &nout)) != 0) {
- (void)fprintf(stderr, "Spooler exit status: %d\n", status);
- (void)fprintf(stderr, "Spooler error message(s):\n");
- for (j = 0; j < nout; j++)
- (void)fprintf(stderr, "\t%s\n", out_buf[j]);
- }
- exit(1);
- }
-
- /*
- * Print job info
- */
- (void)printf("Job submitted\n\n");
- (void)printf("Spooler: \t%s\n",
- (job->spooler == SL_SPOOLER_BSD) ? "BSD":"Sys V");
- (void)printf("Printer: \t%s\n", job->printer);
- (void)printf("File(s): \t%s\n", job->filename);
- (void)printf("User: \t\t%s\n", job->username);
- (void)printf("Job ID: \t%s\n", (job->job_id) ? job->job_id: "Unknown");
- (void)printf("Time: \t\t%s\n", ctime(&job->time_stamp));
-
- return 0;
- }
-
-
- void usage(char *progname)
- {
- (void)fprintf(stderr, "%s [-n #] [-d printer] [-c] [-t title] ", progname);
- (void)fprintf(stderr,
- "[-p spooler options] [-s bsd | sysv] [filename(s)]\n");
- }
-